package com.gxa.insurance.controller;

import com.gxa.insurance.pojo.BringTheOrder;
import com.gxa.insurance.service.BringTheOrderService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @date 2022/6/6
 */
@Api(value = "领标订单模块bring order相关的api接口")
@RestController
@RequestMapping("/bringTheOrder")
@CrossOrigin
public class BringTheOrderController {

    @Autowired
    BringTheOrderService bringTheOrderService;
    @ApiOperation(value = "添加领标订单",produces = "query")
    @PostMapping("/add")
    public Map add(@RequestBody BringTheOrder bringTheOrder,

                   @ApiIgnore HttpSession session){

        Integer add = bringTheOrderService.add(bringTheOrder);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        jsonResult.setData(add);

        return jsonResult.getMap();
    }

    @ApiOperation(value = "更新领标订单详情",produces = "body")
    @ApiImplicitParam(name = "map",value = "实例参数"+"{\n" +
            "\t\"orderId\":\"id\",\n" +
            "\t\"number\":\"20181043022\",\n" +
            "\t\"forensicsDriver\":\"取证司机\",\n" +
            "\t\"alsoTheDriver\":\"换证司机\",\n" +
            "\t\"orderWorkCompany\":\"派工单位\",\n" +
            "\t\"orderStatus\":\"订单状态\",\n" +
            "\t\"inspectPlace\":\"检测场\",\n" +
            "\t\"isMakeCompensation\":\"是否需要赔款\",\n" +
            "\t\"isSendMessage\":\"是否发送短信\",\n" +
            "\t\"attention\":\"特定事项\",\n" +
            "\t\"clientMessageContent\":\"给客户的短信内容\",\n" +
            "\t\"driverMessageContent\":\"给司机的短信内容\",\n" +
            "\t\"getCarTime\":\"接车时间\",\n" +
            "\t\"plateNo\":\"车牌号\",\n" +
            "\t\"engineNumber\":\"发动机号\",\n" +
            "\t\"contactPerson\":\"联系人\",\n" +
            "\t\"contactPhone\":\"联系电话\",\n" +
            "\t\"registerPerson\":\"登记人\",\n" +
            "\t\"receivePosition\":\"接车地点\",\n" +
            "\t\"returnPosition\":\"还车地点\",\n" +
            "\t\"tip\":\"备注\",\n" +
            "\t\"returnTime\":\"预计换车时间\",\n" +
            "\t\"pictureDesc\":\"拍照内容描述\",\n" +
            "\t\"photoAttachments\":\"图片附件\"\n" +
            "\t\"forensicsDriArea\":\"取证司机区域\"\n"+
            "\t\"alsoDriArea\":\"还证司机区域\"\n"+
            "\t\"inspectArea\":\"检测场区域\"\n"+
            "}"
    )
    @PostMapping("/update")
    public Map update(@RequestBody Map<String,String> map) throws Exception {

        Set<Map.Entry<String, String>> entries = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        bringTheOrderService.update(map);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("更新成功");

        return jsonResult.getMap();
    }
}
